package com.yxs.go_bang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManaage {
    // 管理游戏大厅hall在线状态
    private ConcurrentHashMap<Integer, WebSocketSession> gameHall=new ConcurrentHashMap<>();

    //管理游戏房间room在线状态
    private ConcurrentHashMap<Integer,WebSocketSession> gameRoon=new ConcurrentHashMap<>();


    public void enterGameHall(int userId,WebSocketSession webSocketSession){
        gameHall.put(userId,webSocketSession);
    }

    public void exitGameHall(int userId){
        gameHall.remove(userId);
    }

    public WebSocketSession getFromGameHall(int userId){
        return gameHall.get(userId);
    }

    //////////////////////////

    public void enterGameRoom(int userId,WebSocketSession webSocketSession){
        gameRoon.put(userId,webSocketSession);
    }

    public void exitGameRoom(int userId){
        gameRoon.remove(userId);
    }

    public WebSocketSession getFromGameRoom(int userId){
        return gameRoon.get(userId);
    }
}
